<template>
	<view class="home">
		<view class="item">
			<view class="">快递大小:<text>{{Info.size}}</text></view>
			<view class="">快递取件点:<text>{{Info.take_item}}</text></view>
			<view class="">快递送达点:<text>{{Info.give_item}}</text></view>
		</view>
		
		<button type="primary" class="button" @click="nav">确定</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				Info:{},
				TaskIofo:[],
				id:0,
				user_Number:'',
				if_Myself:0
			}
		},
		methods: {
			async getTaskInfo() {
				const res = await this.$myRequest({
					url: 'getTaskInfo'
				})
				this.TaskIofo = res.data.message;
				
				for(let i=0;i<this.TaskIofo.length;i++){
					if(this.TaskIofo[i].id == this.id){
						this.Info = this.TaskIofo[i];
					}
				}
			},
			async OrderReceiving(){
				
				// const res = await this.$myRequest({
				// 	url: `/paoshou_OrderReceiving?id=${this.id}&number=${this.user_Number}`
				// })
				// 改成全局的封装
				const res = await uni.request({
					url:`http://172.16.40.118:8080/paoshou_OrderReceiving?id=${this.id}&number=${this.user_Number}`
				})
				// console.log(res);
				if(res[1].data.code == -1){
					// this.if_Myself = 1;
					uni.showToast({
						title:'该任务为自己发布的信息哦',
						success:()=>{
							return;
						}
					})
				}else{
					uni.showToast({
						title:'接单成功!',
						mask:true,
						duration:800,
						success:()=>{
							let id = setInterval(()=>{
								uni.navigateTo({
									url:'../details_item/details_item?id='+ this.id
								})
								clearInterval(id);
							},1000)
						}
					})
				}
			},
			nav(){
				uni.showModal({
					title:'温馨提醒',
					content:'您确定接手该单嘛？',
					success:(res)=> {
						if(res.confirm){
							this.OrderReceiving();					
						}
						else if(res.cancel){
							console.log('用户点击了取消');
						}
					}
				})
			}
		},
		onLoad(options) {
			this.id = options.id;
			this.user_Number = options.number;
			// console.log(this.id)
			// console.log(this.user_Number);
			this.getTaskInfo();
		},
	}
</script>

<style lang="scss">
	.home{
		width: 100%;
		.item{
			width: 100%;
			font-size: 28rpx;
			margin-top: 20px;
			
			view{
				width: 690rpx;
				height: 140rpx;
				line-height: 140rpx;
				border-bottom: 1px solid #C0C0C0;
				display: flex;
				margin: 0 auto;
				
				text{
					display: block;
					margin-left: 50rpx;
				}
			}
		}
		
		.button{
			position: fixed;
			bottom: 80rpx;
			left:50%;
			font-size: 32rpx;
			transform: translateX(-50%);
			background-color: $main-color;
			width: 90%;
		}
	}
</style>
